package NC500;

public class NC502 {
    public int countLR (int[] a, int[] b) {
        // write code here
        int len = a.length;
        int ans = 0;
        int[][] aValue = new int[a.length][a.length];
        for (int i = 1; i < len; i++) {
            aValue[0][i] = a[i] + aValue[0][i-1];
        }
        for (int i = 0; i < len; i++) {
            if(i>0) aValue[i][i] = aValue[i-1][i] - a[i-1];
            for (int j = i+1; j < len; j++) {
                aValue[i][j] = aValue[i][j-1] + a[j];
            }
        }
        for (int i = 0; i < len; i++) {
            for (int j = i+1; j < len; j++) {
                int temp2 =b[i]+b[j];
                int temp1 = aValue[i][j];
                if(temp1==temp2){
                    ans++;
                }
            }
        }
        return ans;
    }
}